#pragma once

#include "Serializable.h"
#include "TeamAI.h"
#include "Vectors.h"

#include <string>

class ServiceProvider;
class Player;

struct TeamParams
{
	size_t MAX_CHAR_TEAM_NAME;

	size_t STARTING_TEAM_PLAYERS;
	size_t MAX_TEAM_PLAYERS;
	size_t MIN_TEAM_PLAYERS; // must be GREATER OR EQUAL TO TITOLAR_PLAYERS
	
	size_t TITOLARS_GOALKEEPERS;
	size_t TITOLARS_DEFENDERS;
	size_t TITOLARS_ATTACKERS;
	size_t TITOLARS_PLAYERS;
};

struct TeamHistory
{
	int m_totalPodium;
	IntVec m_podium;
	IntVec m_yearsInLeagueLayer;
};

class Team : public Serializable
{
	friend class TeamManager;

public:
	explicit Team(ServiceProvider* const i_sp, const std::string& i_name = "", const size_t i_id = 0);

	static const TeamParams&	GetParams();
	static int			GetRoleByIndex(size_t i_index);
	static int			GetTitolarsByRole(const int i_role);

	void				EndTurnUpdate();

	bool				RemovePlayer(Player* i_player);
	bool				AddPlayer(Player* i_player);
	bool				BuyPlayer(Player* i_player, const size_t price);
	bool				SellPlayer(Player* i_player);
	void				SwapPlayers(int i_first, int i_second);

	int					GetTeamPower() const;

	void				SetName(std::string i_name);
	const std::string&	GetName() const;

	int					GetBudget() const;
	void				AddBudget(int i_budget);

	const PlayerVec&	GetPlayersList() const;
	void				SetPlayersList(const PlayerVec&);

	void				SetUserControlled(bool i_userControlled);
	bool				IsUserControlled() const;

	size_t				GetNumPlayers() const;

	size_t				CalculateTotalSalary() const;

	size_t				GetID() const;

	TeamAI&				GetTeamAI();
	TeamHistory&		GetTeamHistory() {return m_teamHistory;}
	const TeamHistory&	GetTeamHistory() const {return m_teamHistory;}

	int GetTeamPoints(const int i_numYears = 0) const;
	void AddTeamPoints(const int i_points);
	void ClearTeamPoints();

	virtual	ZStream&	Serialize(ZStream& o_stream);
	virtual ZStream&	Deserialize(ZStream& i_stream);

private:
	ServiceProvider*	m_sp;

	static TeamParams	s_params;
	std::string			m_name;
	PlayerVec			m_players;
	int					m_budget;
	bool				m_userControlled;
	size_t				m_id;
	TeamAI				m_ai;
	IntVec				m_teamPoints;
	TeamHistory			m_teamHistory;
};

#include "Team.inl"